import { getToken, setToken, removeToken, removeRoutes, removeCollapse } from '@/utils/session'
import { defineStore } from 'pinia'

export interface UserState {
  token: string
}

export const useUserStore = defineStore('user', {
  state (): UserState {
    return {
      token: getToken()
    }
  },

  actions: {
    SetToken (token: string) {
      setToken(token)
      this.token = token
    },

    Logout () {
      removeToken()
      removeRoutes()
      removeCollapse()
    }
  }
})
